{include file="public/layout" /}

<body class="bodystyle" style="overflow-y: scroll;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
{include file="member/left" /}

<div class="page" style="min-width:auto;margin-left:100px;">
    <div class="fixed-bar">
        <div class="item-title">
            <a class="back_xin" href="{:url('Level/level_index')}" title="返回"><i class="iconfont e-fanhui"></i></a>
            <div class="subject">
                <h3>编辑会员等级</h3>
                <h5></h5>
            </div>
        </div>
    </div>
    <div class="flexigrid">
        <form class="form-horizontal" id="postForm" action="{:url('Level/level_edit')}" method="post">
            <div style="width: 100%;background-color: #f7f7f7;line-height: 36px;padding-left: 10px;color: #555;">基础信息</div>
            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit">
                        <label for="level_name"><em>*</em>等级名称</label>
                    </dt>
                    <dd class="opt">
                        <input id="level_name" name="level_name" value="{$info.level_name}" autocomplete="off" type="text" style="width: 200px;"/>&nbsp;
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit">
                        <label for="rights">等级说明</label>
                    </dt>
                    <dd class="opt">
                        <textarea rows="5" cols="60" name="rights" style="height:60px;">{$info.rights}</textarea>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit">
                        <label for="upgrade">升级条件</label>
                    </dt>
                    <dd class="opt">
                        <label class="curpoin">
                            <input type="radio" name="upgrade" value="1" onclick="changeUpgrade(1);" {eq name="$info.upgrade" value="1"}checked="checked"{/eq} />订单金额
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label class="curpoin">
                            <input type="radio" name="upgrade" value="2" onclick="changeUpgrade(2);" {eq name="$info.upgrade" value="2"}checked="checked"{/eq}/>订单数量
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label class="curpoin">
                            <input type="radio" name="upgrade" value="0"  onclick="changeUpgrade(0);" {eq name="$info.upgrade" value="0"}checked="checked"{/eq}/>不自动升级
                        </label>
                    </dd>
                </dl>
                <dl class="row {eq name="$info.upgrade" value="0"}none{/eq}" id="upgrade_dl" style="margin-left: 114px;">
                    <dt class="tit">
                        <label for="upgrade_val"><em>*</em>
                            {if condition="$info.upgrade == 1"}
                            完成订单金额
                            {elseif  condition="$info.upgrade == 2"}
                            完成订单数量
                            {/if}
                        </label>
                    </dt>
                    <dd class="opt">
                        满&nbsp;&nbsp;<input id="upgrade_val" name="upgrade_val" value="{$info.upgrade_val}" autocomplete="off" type="text" style="width: 60px;text-align: right;" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/>&nbsp;&nbsp;
                        <span>
                            {if condition="$info.upgrade == 1"}
                            元
                            {elseif  condition="$info.upgrade == 2"}
                            单
                            {/if}
                        </span>
                    </dd>
                </dl>
            </div>

            <div style="width: 100%;background-color: #f7f7f7;line-height: 36px;padding-left: 10px;color: #555;">等级权益</div>
            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit">
                        <label for="postage">运费包邮</label>
                    </dt>
                    <dd class="opt">
                        <label class="curpoin">
                            <input type="radio" name="postage" value="0" {eq name="$info.postage" value="0"}checked="checked"{/eq}/>否
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label class="curpoin">
                            <input type="radio" name="postage" value="1" {eq name="$info.postage" value="1"}checked="checked"{/eq}/>是
                        </label>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit">
                        <label for="discount"><em>*</em>消费折扣</label>
                    </dt>
                    <dd class="opt">
                        <input id="discount" name="discount" value="{$info.discount}" autocomplete="off" type="text" style="width: 60px;text-align: right;" onkeyup="this.value=this.value.replace(/[^0-9]/g,''); discountLimit(this);"/>&nbsp;%
                    </dd>
                </dl>
            </div>

            <div class="ncap-form-default">
                <dl class="row">
                    <div class="bot">
                        <input type="hidden" name="level_id" value="{$info.level_id}">
                        <a href="JavaScript:void(0);" onclick="checkSubmit();" class="ncap-btn-big ncap-btn-green"
                           id="submitBtn">确认提交</a>
                    </div>
                </dl>
            </div>
        </form>
    </div>
</div>
<script>
    function changeUpgrade(value) {
        if(0 == value){
            $('#upgrade_dl').hide();
            $('#upgrade_val').value('')
        }else if(1 == value){
            $('#upgrade_dl').show();
            $('#upgrade_dl label').html('<em>*</em>完成订单金额');
            $('#upgrade_dl .opt span').html('元');
            $('#upgrade_val').value('')
        }else if(2 == value){
            $('#upgrade_dl').show();
            $('#upgrade_dl label').html('<em>*</em>完成订单数量');
            $('#upgrade_dl .opt span').html('单');
            $('#upgrade_val').value('')
        }
    }

    // 折扣限制，最大100，最小1
    function discountLimit(obj) {
        var discount = parseInt($(obj).val());
        if (parseInt(discount) > 100) {
            discount = 100;
        } else if (parseInt(discount) < 1 || isNaN(discount)) {
            discount = 1;
        }
        $(obj).val(discount);
    }

    function checkSubmit() {
        if($('input[name=level_name]').val() == ''){
            showErrorMsg('等级名称不能为空！');
            $('input[name=level_name]').focus();
            return false;
        }

        layer_loading('正在处理');
        $.ajax({
            type : 'post',
            url : "{:url('Level/level_edit', ['_ajax'=>1])}",
            data : $('#postForm').serialize(),
            dataType : 'json',
            success : function(res){
                layer.closeAll();
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, shade: layer_shade, time: 1000}, function(){
                        window.location.href = res.url;
                    });
                }else{
                    showErrorMsg(res.msg);
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    }
</script>
{include file="public/footer" /}